package cn.toolck.my.spring.transation;

import cn.toolck.my.spring.annotation.Autowired;
import cn.toolck.my.spring.annotation.Component;
import cn.toolck.my.spring.utils.ConnectionUtils;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.sql.SQLException;

/**
 * @ClassName TransationManager
 * @Description 事务管理器
 * @Author Toolck Rin
 * @Date 2021/2/8 19:02
 * @Version 1.0
 **/
@Component("transationManager")
public class TransationManager {
//        extends InvocationHandler {

    @Autowired
    private ConnectionUtils connectionUtils;

    public void begin() throws SQLException {
        connectionUtils.getConnection().setAutoCommit(false);
        System.out.println("事务开启了");

    }

    public void commit() throws SQLException {
        connectionUtils.getConnection().commit();
        System.out.println("事务提交了");
    }

    public void rollback() throws SQLException {
        connectionUtils.getConnection().rollback();
        System.out.println("事务回滚了");
    }

    public ConnectionUtils getConnectionUtils() {
        return connectionUtils;
    }

    public void setConnectionUtils(ConnectionUtils connectionUtils) {
        this.connectionUtils = connectionUtils;
    }
}
